package com.ruoyi.modules.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wasterTran.dto.OrderDto;
import com.ruoyi.wasterTran.vo.BillStatisticsVo;
import com.ruoyi.wasterTran.vo.WasterTypeDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.modules.mapper.ConstructionWasteTransportationOrderMapper;
import com.ruoyi.modules.domain.ConstructionWasteTransportationOrder;
import com.ruoyi.modules.service.IConstructionWasteTransportationOrderService;

/**
 * 建筑垃圾联运订单信息Service业务层处理
 * 
 * @author ssh
 * @date 2024-12-15
 */
@Service
public class ConstructionWasteTransportationOrderServiceImpl implements IConstructionWasteTransportationOrderService 
{
    @Autowired
    private ConstructionWasteTransportationOrderMapper constructionWasteTransportationOrderMapper;

    /**
     * 查询建筑垃圾联运订单信息
     * 
     * @param id 建筑垃圾联运订单信息主键
     * @return 建筑垃圾联运订单信息
     */
    @Override
    public ConstructionWasteTransportationOrder selectConstructionWasteTransportationOrderById(String id)
    {
        return constructionWasteTransportationOrderMapper.selectConstructionWasteTransportationOrderById(id);
    }

    /**
     * 查询建筑垃圾联运订单信息列表
     * 
     * @param constructionWasteTransportationOrder 建筑垃圾联运订单信息
     * @return 建筑垃圾联运订单信息
     */
    @Override
    public List<ConstructionWasteTransportationOrder> selectConstructionWasteTransportationOrderList(ConstructionWasteTransportationOrder constructionWasteTransportationOrder)
    {
        return constructionWasteTransportationOrderMapper.selectConstructionWasteTransportationOrderList(constructionWasteTransportationOrder);
    }

    /**
     * 新增建筑垃圾联运订单信息
     * 
     * @param constructionWasteTransportationOrder 建筑垃圾联运订单信息
     * @return 结果
     */
    @Override
    public int insertConstructionWasteTransportationOrder(ConstructionWasteTransportationOrder constructionWasteTransportationOrder)
    {
        constructionWasteTransportationOrder.setCreateTime(DateUtils.getNowDate());
        return constructionWasteTransportationOrderMapper.insertConstructionWasteTransportationOrder(constructionWasteTransportationOrder);
    }

    /**
     * 修改建筑垃圾联运订单信息
     * 
     * @param constructionWasteTransportationOrder 建筑垃圾联运订单信息
     * @return 结果
     */
    @Override
    public int updateConstructionWasteTransportationOrder(ConstructionWasteTransportationOrder constructionWasteTransportationOrder)
    {
        constructionWasteTransportationOrder.setUpdateTime(DateUtils.getNowDate());
        return constructionWasteTransportationOrderMapper.updateConstructionWasteTransportationOrder(constructionWasteTransportationOrder);
    }

    /**
     * 批量删除建筑垃圾联运订单信息
     * 
     * @param ids 需要删除的建筑垃圾联运订单信息主键
     * @return 结果
     */
    @Override
    public int deleteConstructionWasteTransportationOrderByIds(String[] ids)
    {
        return constructionWasteTransportationOrderMapper.deleteConstructionWasteTransportationOrderByIds(ids);
    }

    /**
     * 删除建筑垃圾联运订单信息信息
     * 
     * @param id 建筑垃圾联运订单信息主键
     * @return 结果
     */
    @Override
    public int deleteConstructionWasteTransportationOrderById(String id)
    {
        return constructionWasteTransportationOrderMapper.deleteConstructionWasteTransportationOrderById(id);
    }

    @Override
    public List<BillStatisticsVo> selectOrderCount(OrderDto orderDto) {
        if(orderDto.getType().equals("0")){
            return constructionWasteTransportationOrderMapper.selectOrderYearsCount(orderDto);
        }else if(orderDto.getType().equals("1")){
            return constructionWasteTransportationOrderMapper.selectOrderMothsCount(orderDto);
        }else{
            return constructionWasteTransportationOrderMapper.selectOrderDaysCount(orderDto);
        }

    }

    @Override
    public List<WasterTypeDataVo> selectOrderWasterTypeCount(OrderDto orderDto) {
        return constructionWasteTransportationOrderMapper.selectOrderWasterTypeCount(orderDto);
    }


    /**
     *  联单总数,运输总量, 运输次数 ,处置总量
     * @return
     * @param orderDto
     */
    @Override
    public List<Map<String, Object>> countNum(OrderDto orderDto) {
        // 统计  联单总数  运输次数  所有运输状态的总量和次数
        Map<String, Object> mp = constructionWasteTransportationOrderMapper.countNum(orderDto);

        // 运输总量 处置总量  已完成
        Map<String, Object> mpWanCheng = constructionWasteTransportationOrderMapper.countWanChengNum(orderDto);

        List<Map<String, Object>> resultList = new ArrayList<>();
            Map<String, Object> mapp = new HashMap<>();
              mapp.put("title", "联单总数");
              mapp.put("value", mp.get("ldCount").toString());
            resultList.add(mapp);

            Map<String, Object> mapp1 = new HashMap<>();
                mapp1.put("title", "运输次数");
                mapp1.put("value", mp.get("ysCount").toString());
            resultList.add(mapp1);



            Map<String, Object> mapp2 = new HashMap<>();
                mapp2.put("title", "运输总量");
                if(null !=mpWanCheng && mpWanCheng.containsKey("ysSum")){
                    mapp2.put("value", mpWanCheng.get("ysSum").toString());
                }else{
                    mapp2.put("value", 0);
                }

                 resultList.add(mapp2);

            Map<String, Object> mapp3 = new HashMap<>();
                mapp3.put("title", "处置总量");
                if(null !=mpWanCheng && mpWanCheng.containsKey("ysSum")){
                    mapp3.put("value", mpWanCheng.get("czSum").toString());
                }else{
                    mapp3.put("value", 0);
                }

                resultList.add(mapp3);

        return resultList;
    }

    /**
     *  状态分布
     * @return
     */
    @Override
    public List<Map<String, Object>> selectOrderByStatus(OrderDto orderDto) {
        return constructionWasteTransportationOrderMapper.selectOrderByStatus(orderDto);
    }

    /**
     *  联单统计列表
     * @return
     */
    @Override
    public List<Map<String, Object>> selectOrderList(OrderDto orderDto) {
        return constructionWasteTransportationOrderMapper.selectOrderList(orderDto);
    }

    /**
     *  工地区域分布统计
     */
    @Override
    public List<Map<String, Object>> selectConstructionSiteArea(OrderDto orderDto) {
        return constructionWasteTransportationOrderMapper.selectConstructionSiteArea(orderDto);
    }
}
